def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def add_player():
""" Adds a player to the stage for the user to control """
player = codesters.Sprite("player1")
player.go_to(0, -155)
return player
def add_ball():
""" Adds a ball to the stage and sets its attributes """
ball = codesters.Sprite("soccerball")
ball.set_y_speed(-8)
def main():
""" Sets up the program and calls other functions """
set_stage()
player = add_player()
main()
t = codesters.Teacher()
defs = t.find_block("def")
add_balls = t.find_text("add_ball")
my_functions = t.find_text("my_function")
def get_above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
try:
tval1 = add_balls[1][1].replace(' ','').lower()
tval1_line_num = add_balls[1][0]
tval1_indent = t.get_indent_at_line(tval1_line_num)
except:
tval1 = "DNE"
tval1_line_num = "DNE"
tval1_indent = "DNE"
try:
tval1_def, tval1_distance = get_above_def(tval1_line_num, defs)
except:
tval1_def = "DNE"
tval1_distance = "DNE"
t1 = TestObjective()
t1.add_success(tval1 != "DNE", "Great job!")
t1.add_failure(tval1 == "DNE" and len(my_functions) == 0, "Did you add Function Call inside add_ball()?")
t1.add_failure(tval1 == "DNE" and len(my_functions) > 0, "Did you change my_function() to add_ball()?")
t2 = TestObjective()
t2.add_success("main" in tval1_def and tval1_indent == 4, "Great job!")
t2.add_failure("main" not in tval1_def, "Did you add Function Call inside the main() function?")
t2.add_failure(tval1_indent < 4 or tval1_indent > 4, "Make sure Function Call is indented inside main()!")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)